﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace SAIN.Wuc
{
    public partial class wucMoodal : System.Web.UI.UserControl
    {        

        #region "Propiedades"

        public string Titulo
        {
            get
            {
                return this.lblTitulo.Text;
            }

            set
            {
                this.lblTitulo.Text = value;                
            }
        }

        public string Mensaje
        {
            get
            {
                return this.lblMensaje.Text;
            }

            set
            {
                this.lblMensaje.Text = value;                
            }
        }

        private MoodalTipo _tipo;
        public MoodalTipo Tipo
        {
            get 
            { 
                return _tipo; 
            }

            set
            {
                _tipo = value;
                ViewState[this.UniqueID + "_tipo"] = _tipo;

                EstablecerCssTipo();
            }
        }

        private bool? _visible;
        public bool Visible
        {
            get
            {
                return this.pnControl.Visible;
            }
            set
            {
                this.pnControl.Visible = value;
            }
        }

        /*
        public bool? Show
        {
            get
            {
                return _visible;
            }

            set
            {                
                _visible = value;
                ViewState[this.UniqueID + "_visible"] = _visible;

                if (value != null)                    
                        this.ResizeImageHACK((bool)value);

                string[] separadores = {" "};
                string[] cssClasses = this.pnControl.CssClass.Split(separadores, StringSplitOptions.RemoveEmptyEntries);

                this.pnControl.CssClass = "";
                foreach (string css in cssClasses)
                {
                    switch (this._visible)
                    {                        
                        case true:
                            this.pnControl.CssClass += (css.ToUpper() == "INVISIBLE") ? "" : css + " ";
                            break;
                        case null:
                        case false:
                            this.pnControl.CssClass += (css.ToUpper() == "VISIBLE") ? "" : css + " ";
                            break;
                    }
                }

                this.pnControl.CssClass += (this._visible == false || this._visible == null) ? "Invisible" : "Visible";                
            }
        }
        */
        #endregion

        #region "Eventos"

        public event System.EventHandler OkClickButton;
        public event System.EventHandler SiClickButton;
        public event System.EventHandler NoClickButton;       

        protected void Page_Load(object sender, EventArgs e)
        {            
            EstablecerViewState();

            if (!Page.IsPostBack)
            {
                //CssClass Default del Control.
                this.pnControl.CssClass = "wucMoodal Invisible" + this.pnControl.CssClass;
                //Si no se establece un valor en la propiedad Show del control, esta sera FALSE por default.
                //if (this.Show == null)
                  //  this.Show = false;                    
                    this.EstablecerCssTipo();
            }

            this.btnOk.Visible = false;
            this.btnSi.Visible = false;
            this.btnNo.Visible = false;

            if (this.OkClickButton != null)
                this.btnOk.Visible = true;
            if (this.SiClickButton != null)
                this.btnSi.Visible = true;
            if (this.NoClickButton != null)
                this.btnNo.Visible = true;            
        }

        protected void btnOk_Click(object sender, EventArgs e)
        {
            if (OkClickButton != null)
                OkClickButton(sender, e);
        }

        protected void btnSi_Click(object sender, EventArgs e)
        {
            if (SiClickButton != null)
                SiClickButton(sender, e);
        }

        protected void btnNo_Click(object sender, EventArgs e)
        {
            if (NoClickButton != null)
                NoClickButton(sender, e);
        }

        #endregion

        #region "Metodos"

        private void EstablecerViewState()
        {
            if (ViewState[this.UniqueID + "_tipo"] != null)
                this._tipo = (MoodalTipo)ViewState[this.UniqueID + "_tipo"];
            if (ViewState[this.UniqueID + "_visible"] != null)
                this._visible = (bool?)ViewState[this.UniqueID + "_visible"];
        }

        private void EstablecerCssTipo()
        {
            switch (this.Tipo)
            {
                case MoodalTipo.Exito:
                    this.EstablecerCssControl("TExito", "IExito", "DExito");
                    break;
                case MoodalTipo.Error:
                    this.EstablecerCssControl("TError", "IError", "DError");
                    break;
                case MoodalTipo.Advertencia:
                    this.EstablecerCssControl("TAdvertencia", "IAdvertencia", "DAdvertencia");
                    break;
                case MoodalTipo.Informacion:
                    this.EstablecerCssControl("TInformacion", "IInformacion", "DInformacion");
                    break;
                case MoodalTipo.Confirmacion:
                    this.EstablecerCssControl("TConfirmacion", "IConfirmacion", "DConfirmacion");
                    break;

            }
        }

        private void EstablecerCssControl(string cssTitulo, string cssIcon, string cssDialogo)
        {
            this.lblTitulo.CssClass = "Titulo " + cssTitulo;
            this.pnIcon.CssClass = "Icon " + cssIcon;
            this.pnDialogo.CssClass = "Dialogo " + cssDialogo;
        }        

        #endregion
    }
}